// pages/after/after.js
const ipUtil = require("../../utils/hostUtil")
const requestUtil = require("../../utils/requestUtil")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({title: '评价中心'})
    this.loadPage()
  },

  loadPage:function(){
    var token = wx.getStorageSync("token")
    console.log(token)
    var that = this
    wx.request({
      url: `${ipUtil.host}${requestUtil.after}`,
      method: "POST",
      header: requestUtil.header,
      data:{token:token},
      success(res){
		  console.log(res)
        that.list = res.data.rows
        let result = []
        if(!that.list){
          return;
        }
        that.list.forEach(item => {
          that.lists=item.order.orderVoList
          that.lists.forEach(item=>{
            result.push({
              mainImg:item.mainImg,
              fruitName:item.fruitName,
              price:item.price
            })
          })
        })
        that.setData({
          list:result
        })
      }
    })
  },
  
  to_detail:function(e){
	  let id = e.currentTarget.dataset.id
	  wx.navigateTo({
		  url:`/pages/detail/detail?id=${id}`
	  })
  },

  delete:function(e){
    var that = this
    wx.showModal({
      title: '提示',
      content: '您确定要删除吗',
      success: function (res) {
        if(res.confirm){
          that.data.list.splice(e.currentTarget.dataset.index,1)
          console.log(e.currentTarget.dataset.index)
          that.setData({
            list:that.data.list
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})